﻿<div class="page-container" id="admui-pageContent">
    <div class="page animation-fade page-forms">
        <div class="page-content">
            <div class="panel">
                <div class="page-header">
                    <h1 class="page-title">人员列表</h1>
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a class="icon wb-home" href="javascript:;">人员管理</a>
                        </li>
                        <li class="breadcrumb-item active">人员列表</li>
                    </ol>
                </div>
                <div class="panel-body">
                    <h4 class="example-title">数据查询</h4>
                    <div class="row">
                        <div class="form-group col-sm-3">
                            <label class="col-form-label" for="for_XingBie">姓名</label>
                            <input id="XingMing" class="form-control" placeholder="姓名"/>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="control-label" for="inputBasicPassword">公司</label>
                            <select id="SelGongSi" class="form-control"></select>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="col-form-label" for="for_XingBie">部门</label>
                            <select id="SelBuMen" class="form-control"></select>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="col-form-label" for="for_XingBie">岗位</label>
                            <select id="SelGangWei" class="form-control"></select>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="col-form-label" for="for_XingBie">战区</label>
                            <select id="SelZhanQu" class="form-control">
                            </select>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="col-form-label" for="for_XingBie">战队</label>
                            <select id="SelZhanDui" class="form-control">
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="padding-top:27px">
                            <button type="button" id="bt_ChaXun" class="btn btn-block btn-success" style="width: 95%; float: left;" onclick="bang('查')"><i class="icon wb-search"></i>查询</button>
                        </div>
                        <div class="form-group col-sm-3" style="padding-top:27px">
                            <button typeutton" id="bt_ChongZhi" class="btn btn-outline btn-success" style="width: 95%;" onclick="chongzhi();">重置</button>
                        </div>
                    </div>
                </div>
                <div class="panel-body" style="margin-top:-50px">
                    <table class="table table-bordered table-hover dataTable table-striped w-full text-nowrap" id="dataTableExample" data-plugin="dataTable">
                        <thead>
                            <tr>
                                <th>姓名</th>
                                <th>年龄</th>
                                <th>性别</th>
                                <th>联系方式</th>
                                <th>部门</th>
                                <th>岗位</th>
                                <th>公司</th>
                                @*<th>战区</th>
                                    <th>战队</th>*@
                                <th>身份证号</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <th>姓名</th>
                                <th>年龄</th>
                                <th>性别</th>
                                <th>联系方式</th>
                                <th>部门</th>
                                <th>岗位</th>
                                <th>公司</th>
                                @*<th>战区</th>
                                    <th>战队</th>*@
                                <th>身份证号</th>
                                <th>操作</th>
                            </tr>
                        </tfoot>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
            <script type="text/javascript">
                $(document).ready(function () {
                    $("#SpanRenYuan").click();
                    bang('不查');
                    bangdingshuju();
                    $("#SelBuMen").append("<option value='0'>请选择</option>");
                    $("#SelGangWei").append("<option value='0'>请选择</option>");
                    $("#SelZhanDui").append("<option value='0'>请选择</option>");

                    $('#SelGongSi').change(function () {
                        var selGongSi = $("#SelGongSi").find("option:selected").val();
                        if (selGongSi != "0") {
                            $('#SelBuMen option').remove();
                            $('#SelGangWei option').remove();
                            $("#SelGangWei").append("<option value='0'>请选择</option>");
                            bumen(selGongSi);
                        } else {
                            $('#SelBuMen option').remove();
                            $('#SelGangWei option').remove();
                            $("#SelBuMen").append("<option value='0'>请选择</option>");
                            $("#SelGangWei").append("<option value='0'>请选择</option>");
                        }
                    })

                    $('#SelZhanQu').change(function () {
                        var selZhanQu = $("#SelZhanQu").find("option:selected").val();
                        if (selZhanQu != "0") {
                            $('#SelZhanDui option').remove();
                            zhandui(selZhanQu);
                        } else {
                            $('#SelZhanDui option').remove();
                            $("#SelZhanDui").append("<option value='0'>请选择</option>");
                        }
                    })

                    $('#SelBuMen').change(function () {
                        var selBuMen = $("#SelBuMen").find("option:selected").val();
                        if (selBuMen != "0") {
                            $('#SelGangWei option').remove();
                            gangwei(selBuMen);
                        } else {
                            $('#SelGangWei option').remove();
                            $("#SelGangWei").append("<option value='0'>请选择</option>");
                        }
                    })

                });

                function zhandui(ZhanQuId) {
                    $.ajax({
                        url: "../RenYuan/GetSelZhanDui",
                        data: { "ZhanQuId": ZhanQuId },
                        type: "post",
                        dataType: "json",
                        success: function (date) {
                            var ddl = $("#SelZhanDui");
                            ddl.append("<option value='0'>请选择</option>");
                            $(date).each(function (key) {
                                if (date[key].id == "1") {

                                } else {
                                    var opt = $("<option></option>").text(date[key].ZhanDuiMingCheng).val(date[key].id);
                                    ddl.append(opt);
                                }
                            })
                        }
                    });
                }

                function bumen(GongSiId) {
                    $.ajax({
                        url: "../RenYuan/GetSelBuMen",
                        type: "post",
                        data: { "GongSiId": GongSiId },
                        dataType: "json",
                        success: function (date) {
                            var ddl = $("#SelBuMen");
                            ddl.append("<option value='0'>请选择</option>");
                            $(date).each(function (key) {
                                if (date[key].Id == "1") {

                                } else {
                                    var opt = $("<option></option>").text(date[key].BuMenMingCheng).val(date[key].Id);
                                    ddl.append(opt);
                                }
                            })
                        }
                    });
                }

                function gangwei(BuMenId) {
                    $.ajax({
                        url: "../RenYuan/GetSelGangWei",
                        type: "post",
                        data: { "BuMenId": BuMenId },
                        dataType: "json",
                        success: function (date) {
                            var ddl = $("#SelGangWei");
                            ddl.append("<option value='0'>请选择</option>");
                            $(date).each(function (key) {
                                if (date[key].Id == "1") {

                                } else {
                                    var opt = $("<option></option>").text(date[key].GangWeiMingCheng).val(date[key].Id);
                                    ddl.append(opt);
                                }
                            })
                        }
                    });
                }

                function bangdingshuju() {
                    $.ajax({
                        type: 'post',
                        url: "../RenYuan/GetSelGongSi",
                        async: false,
                        dataType: 'json',
                        success: function (date) {
                            var ddl = $("#SelGongSi");
                            ddl.append("<option value='0'>请选择</option>");
                            $(date).each(function (key) {
                                if (date[key].Id == "1") {

                                } else {
                                    var opt = $("<option></option>").text(date[key].GongSiMingCheng).val(date[key].Id);
                                    ddl.append(opt);
                                }
                            })
                        },
                    })

                    $.ajax({
                        type: 'post',
                        url: "../RenYuan/GetSelZhanQu",
                        async: false,
                        dataType: 'json',
                        success: function (date) {
                            var ddl = $("#SelZhanQu");
                            ddl.append("<option value='0'>请选择</option>");
                            $(date).each(function (key) {
                                if (date[key].Id == "1") {

                                } else {
                                    var opt = $("<option></option>").text(date[key].ZhanQuMingCheng).val(date[key].Id);
                                    ddl.append(opt);
                                }
                            })
                        },
                    })
                }


                function chongzhi() {
                    $('#SelBuMen option').remove();
                    $('#SelGangWei option').remove();
                    $('#SelZhanDui option').remove();
                    $('#SelGongSi option').remove();
                    $('#SelZhanQu option').remove();
                    $("#SelBuMen").append("<option value='0'>请选择</option>");
                    $("#SelGangWei").append("<option value='0'>请选择</option>");
                    $("#SelZhanDui").append("<option value='0'>请选择</option>");
                    $("#XingMing").val('');
                    bang('不查')
                    bangdingshuju();
                }
                function bang(panduan) {
                    var xingming = "";
                    var selGongSi = "0";
                    var selZhanQu = "0";
                    var selZhanDui = "0";
                    var selBuMen = "0";
                    var selGangWei = "0";
                    if (panduan == "查") {
                        xingming = $("#XingMing").val();
                        selGongSi = $("#SelGongSi").find("option:selected").val();
                        selZhanQu = $("#SelZhanQu").find("option:selected").val();;
                        selZhanDui = $("#SelZhanDui").find("option:selected").val();;
                        selBuMen = $("#SelBuMen").find("option:selected").val();;
                        selGangWei = $("#SelGangWei").find("option:selected").val();;
                    } else if (panduan == "不查") {
                        xingming = "";
                        selGongSi = "0";
                        selZhanQu = "0";
                        selZhanDui = "0";
                        selBuMen = "0";
                        selGangWei = "0";
                    }
                    var lang = {
                        "sProcessing": "大量处理中，请稍后...",
                        "sLengthMenu": "每页 _MENU_ 项",
                        "sZeroRecords": "没有匹配结果",
                        "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
                        "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
                        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                        "sInfoPostFix": "",
                        "sSearch": "搜索:",
                        "sUrl": "",
                        "sEmptyTable": "表中数据为空",
                        "sLoadingRecords": "载入中...",
                        "sInfoThousands": ",",
                        "oPaginate": {
                            "sFirst": "首页",
                            "sPrevious": "上页",
                            "sNext": "下页",
                            "sLast": "末页",
                            "sJump": "跳转"
                        },
                        "oAria": {
                            "sSortAscending": ": 以升序排列此列",
                            "sSortDescending": ": 以降序排列此列"
                        }
                    };
                    $("#dataTableExample").dataTable().fnDestroy();
                    $('#dataTableExample').dataTable({
                        "order": [[1, "asc"]],
                        "language": lang,
                        "processing": true,
                        "serverSide": true,
                        //"bStateSave": true,//状态保持模式
                        "searching": false,//禁用搜索
                        ajax: function (data, callback, settings) {
                            //封装请求参数 
                            //console.log(data);
                            var param = {};
                            param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                            param.start = data.start;//开始的记录序号
                            param.page = (data.start / data.length) + 1;//当前页码
                            param.dir = data.order[0].dir;
                            param.column = data.order[0].column;
                            param.xingming = xingming;
                            param.selZhanQu = selZhanQu;
                            param.selZhanDui = selZhanDui;
                            param.selGangWei = selGangWei;
                            param.selGongSi = selGongSi;
                            param.selBuMen = selBuMen;
                            param.ZhuangTai = '在职';
                            //console.log(param);

                            //ajax请求数据
                            $.ajax({
                                type: "POST",
                                url: "../RenYuan/InitializationDataTable",
                                cache: false,  //禁用缓存
                                data: param,  //传入组装的参数
                                dataType: "json",
                                success: function (result) {
                                    console.log(result);
                                    //setTimeout仅为测试延迟效果
                                    setTimeout(function () {
                                        //封装返回数据
                                        var returnData = {};
                                        returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
                                        returnData.recordsTotal = result.total;//返回数据全部记录
                                        returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                                        returnData.data = result.data;//返回的数据列表
                                        //console.log(returnData);
                                        //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
                                        //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕"orderable" : false
                                        callback(returnData);
                                    }, 200);
                                }
                            });
                        },
                        "columns": [
                            { "data": "XingMing" },
                            { "data": "NianLing" },
                            { "data": "XingBie" },
                            { "data": "LianXiFangShi" },
                            { "data": "t_GangWeiBiao.t_BuMenBiao.BuMenMingCheng" },
                            { "data": "t_GangWeiBiao.GangWeiMingCheng" },
                            { "data": "t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.GongSiMingCheng" },
                            //{ "data": "t_ZhanDuiBiao.t_ZhanQuBiao.ZhanQuMingCheng" },
                            //{ "data": "t_ZhanDuiBiao.ZhanDuiMingCheng" },
                            { "data": "ShenFenZhengHao" },
                            { "data": null }
                        ],
                        columnDefs: [{
                            //   指定第最后一列
                            targets: -1,
                            //加下面属性 不参与排序
                            sortable: false,
                            render: function (data, type, row, meta) {
                                return '<button type="button" class="btn btn-outline btn-default" onclick="shebeiXG(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>修改</button>' +
                                    '<button type="button" class="btn btn-outline btn-default" onclick="ChaXu(' + row.Id + ')"><i class="icon wb-search"></i>查询</button>' +
                                    '<button type="button" class="btn btn-outline btn-default" onclick="fire(' + row.Id + ')"><i class="icon wb-search"></i>开除</button>' +
                                    '<button type="button" class="btn btn-outline btn-default" onclick="xg(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>解除绑定</button>';
                            }
                        }]
                    });
                }

                function ChaXu(Id) {
                    location.href = "../RenYuan/RenYuanXiangXi?id=" + Id;
                }

                function login() {
                    $.ajax({
                        url: "../HuiYuan/addhuiyuan",
                        data: { "qiyeid": $("#qiyeid").val(), "xingming": $("#xingming").val(), "lianxi": $("#lianxi").val(), "shenfenzheng": $("#shenfenzheng").val() },
                        type: "post",
                        dataType: "text",
                        success: function (response) {
                            if (response == "success") {
                                location.href = "../HuiYuan/List";
                            }
                        }
                    });
                }
                function xg(id) {
                    $.ajax({
                        url: "../RenYuan/Modify2",
                        data: { Id: id },
                        type: "post",
                        dataType: "text",
                        success: function (response) {
                            if (response == "success") {
                                alert('解除绑定成功');
                            } else if (response == "") {
                                alert("已经解绑");
                            } else {
                                alert('解除绑定失败');
                            }
                        }
                    });
                }
                function shebeiXG(id) {
                    location.href = "../RenYuan/CreateAndModify?id=" + id;
                }
                function fire(id) {
                    $.ajax({
                        url: "../RenYuan/KaiChu",
                        data: { "RebYuanId": id },
                        type: "post",
                        dataType: "text",
                        success: function (response) {
                            if (response == "success") {
                                alert("成功");
                            } else {
                                alert("失败");
                            }
                        }
                    });
                }
            </script>
        </div>
    </div>
</div>